package com.zensun.framework.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.zensun.common.utils.DateUtils;
import com.zensun.system.util.SecurityUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

/**
 * mp的自动填充
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createBy", SecurityUtils.getLoginUser().getUser().getUserId(), metaObject);
        this.setFieldValByName("createTime", DateUtils.getNowDate(), metaObject);
        this.setFieldValByName("updateBy", SecurityUtils.getLoginUser().getUser().getUserId(), metaObject);
        this.setFieldValByName("updateTime", DateUtils.getNowDate(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateBy", SecurityUtils.getLoginUser().getUser().getUserId(), metaObject);
        this.setFieldValByName("updateTime", DateUtils.getNowDate(), metaObject);
    }
}
